<!-- 编辑窗口 -->
<div class="mar-st-a30">
	<form class="form-horizontal" role="form" action="#" id="dataForm">
		<input id="type" name="type" type="hidden" value="{{settingVo.type}}"></input>
		<input id="id" name="id" type="hidden" value="{{settingVo.id}}"></input>
		<div class="form-group">
			<label for="name" class="col-lg-2 control-label">名称</label>
			<div class="col-lg-10">
				<input type="text" class="form-control wid60" id="name" name="name"
					value="{{settingVo.name}}" required placeholder="请输入名称"
					>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript">

	var popover = function(inputId, errorMsg) {
		var el = $('#' + inputId);
		var controls = el.parent().find('.a');
		var len = controls.length;
		if (errorMsg) {
			var cls = (el.attr('btvd-class') == undefined) ? null : el.attr(
					'btvd-class').split(' ');
			if (len <= 0) {
				el
						.after('<input class="a"  style=" visibility:hidden;" data-placement="bottom"  data-content="'+errorMsg+ '"  data-toggle="popover"/>');
			}
			controls.attr("data-content", errorMsg);
			controls.show();
			el.next().popover("show");
			var pop = el.parent().find(".popover"), pos = pop.offset();
			pos.top = pos.top - el.next().height();
			pop.offset(pos);
			if (cls)
				pop.addClass("btvdclass");

		} else {
			controls.popover("hide");
			controls.hide();
		}
	}
	function checkName(name) {
		var oldName = "{{settingVo.name}}";
		if (oldName != name) {
			var tel =/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/; 
			 var flag = tel.test(name);
			 if(!flag){
				 popover("name", "名称不能包含特殊字符，请换别的试试！");
				$("#name").val("");
				return false;
			 }
			
			var data = {
				name : name
			};
			var isOK = false;
			$.ajax({
				async : false,
				type : "POST",
				url : "{{ctx}}/mam/setting/check/{{settingVo.type}}",
				data : data,
				dataType : 'json',
				success : function(data, textStatus) {
					if (data.result == "true") {
						popover("name","名称已经存在，请换别的试试");
						$('#name').val("");
					}else{
						isOK = true;
					}
				},
				error : function(data, status, e) {
					bootbox.alert("系统繁忙，请稍后再试！");
					
				}
			});
			return isOK;
		}
		return true;
	}
	//提交表单，进行打包
	function submitForm(platformid) {
		var name = $('#name').val();
		if (name == "") {
			popover("name","请填写名称");
		} else if(checkName(name)) {
			var data = $('#dataForm').serialize();
			$.ajax({
				async : true,
				type : "POST",
				url : "{{ctx}}/mam/setting/update",
				data : data,
				dataType : 'json',
				success : function(data, textStatus) {
					bootbox.alert("修改成功", function() {
						window.location.reload();
					})
				},
				error : function(data, status, e) {
					bootbox.alert("系统繁忙，请稍后再试！");
				}
			});
		}
	}
</script>
